<?php

namespace frontend\models;

use Yii;
use \common\models\DhWebAd;

/**
 * This is the model class for table "dh_news".
 *
 * @property integer $GeneralID
 * @property integer $NodeID
 * @property integer $ModelID
 * @property integer $ItemID
 * @property string $TableName
 * @property string $Title
 * @property string $Inputer
 * @property integer $Hits
 * @property integer $DayHits
 * @property integer $WeekHits
 * @property integer $MonthHits
 * @property integer $LinkType
 * @property string $UpdateTime
 * @property string $CreateTime
 * @property string $TemplateFile
 * @property integer $Status
 * @property integer $EliteLevel
 * @property integer $Priority
 * @property integer $CommentAudited
 * @property integer $CommentUnAudited
 * @property integer $SigninType
 * @property string $InputTime
 * @property string $PassedTime
 * @property string $Editor
 * @property string $LastHitTime
 * @property string $DefaultPicUrl
 * @property string $PinyinTitle
 * @property string $TitleFontColor
 * @property string $TitleFontType
 * @property string $IncludePic
 * @property integer $ShowCommentLink
 * @property string $TitleHashKey
 * @property string $HtmlPageName
 * @property integer $SGType
 * @property integer $img_id
 * @property integer $SGDataId
 * @property string $address
 * @property integer $stick
 * @property string $address_name
 */
class DhNews extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'dh_news';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['NodeID', 'Title'], 'required'],
            [['NodeID', 'ModelID', 'ItemID', 'Hits', 'DayHits', 'WeekHits', 'MonthHits', 'LinkType', 'Status', 'EliteLevel', 'Priority', 'CommentAudited', 'CommentUnAudited', 'SigninType', 'ShowCommentLink', 'SGType', 'img_id', 'SGDataId', 'stick'], 'integer'],
            [['UpdateTime', 'CreateTime', 'InputTime', 'PassedTime', 'LastHitTime'], 'safe'],
            [['PinyinTitle', 'address'], 'string'],
            [['TitleHashKey'], 'number'],
            [['TableName', 'Title', 'Inputer', 'TemplateFile', 'Editor', 'DefaultPicUrl', 'TitleFontColor', 'TitleFontType', 'IncludePic', 'HtmlPageName', 'address_name'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'GeneralID' => '内容全局ID',
            'NodeID' => '节点ID',
            'ModelID' => '模型ID',
            'ItemID' => '相应表的记录ID',
            'TableName' => '模型表名',
            'Title' => '标题',
            'Inputer' => '录入者',
            'Hits' => '点击数',
            'DayHits' => '日点击数',
            'WeekHits' => '周点击数',
            'MonthHits' => '月点击数',
            'LinkType' => '链接类型',
            'UpdateTime' => '更新时间',
            'CreateTime' => '生成时间',
            'TemplateFile' => '该文章所使用的模板路径',
            'Status' => '信息状态 -3为删除，-2为退稿，-1为草稿，0为待审核，99为终审通过，其它为自定义',
            'EliteLevel' => '推荐级别',
            'Priority' => '优先级别',
            'CommentAudited' => '通过审核的评论总数',
            'CommentUnAudited' => '未通过审核的评论总数',
            'SigninType' => '签收类型',
            'InputTime' => '文章录入时间',
            'PassedTime' => '审核通过时间',
            'Editor' => '编辑',
            'LastHitTime' => '上次点击时间',
            'DefaultPicUrl' => '默认首页图片',
            'PinyinTitle' => '拼音标题',
            'TitleFontColor' => '标题字体颜色',
            'TitleFontType' => '标题字形',
            'IncludePic' => '标题前缀  1--[图文]  2--[组图]  3--[推荐]  4--[注意]',
            'ShowCommentLink' => '列表显示时是否在标题旁显示“评论”链接',
            'TitleHashKey' => '标题Hash值',
            'HtmlPageName' => '静态页名称',
            'SGType' => '站群信息类型',
            'img_id' => '图片ID',
            'SGDataId' => '站群数据ID',
            'address' => '链接地址',
            'stick' => 'Stick',
            'address_name' => '附件名称',
        ];
    }
    public function getBaseImg(){
        return $this->hasOne(DhBaseImg::className(),['id'=>'img_id']);
    }
    
    
    
    public static function GetListPage( $id,$begin = 0,$page = 5 ){
        $newList = DhNews::find()->where(["NodeID"=>$id,"Status"=>99])->orderBy("stick DESC,(case  when  Priority IS NULL  then 99999999 else Priority end),Priority ASC,UpdateTime DESC")->limit($page)->offset($begin)->asArray()->all();
        return $newList;
        
    }
    
    public static function GetListImg($id,$begin = 0,$page = 5 ){
        $newList = DhNews::find()->where(["NodeID"=>$id,"Status"=>99])->joinWith("baseImg")->orderBy("stick DESC,(case  when  Priority IS NULL  then 99999999 else Priority end),Priority ASC,UpdateTime DESC")->limit($page)->offset($begin)->asArray()->all();
        return $newList;
    }
    
    public static function GetListImgOne($id,$begin = 0,$page = 5 ){
        $newList = DhNews::find()->where(["NodeID"=>$id,"Status"=>99])->joinWith("baseImg")->orderBy("stick DESC,(case  when  Priority IS NULL  then 99999999 else Priority end),Priority ASC,UpdateTime DESC")->limit($page)->offset($begin)->asArray()->one();
        return $newList;
    }
    
    public static function GetPeoList( ){
        $newList = DhWebAd::find()->where(["status"=>1])->joinWith("webImg")->orderBy("created_at DESC")->limit(8)->offset(0)->asArray()->all();
//        print_r($newList);
//        die();
        return $newList;
    }
    
    public static function getNodeName(){
        $name = \frontend\models\DhType::find()->orderBy("OrderID DESC")->asArray()->all();
        return $name;
//        print_r($name);die();
    }
}
